package report4.classes;

import java.util.ArrayList;
import java.util.List;

/**
 * 记录每次请求状态
 *
 * @author zouran
 * createDate：2023/5/17  20:54
 */
public class Page {
    //记录当前内存中的页
    private List<Integer> list = new ArrayList<>();
    //当前请求访问页面
    private Integer current;
    //缺页中断
    private boolean interrupt;
    //访问位
    private boolean[] request = new boolean[100];

    public Page(List<Integer> list, Integer current, boolean interrupt) {
        this.list = list;
        this.current = current;
        this.interrupt = interrupt;
    }

    public Page(List<Integer> list, boolean[] request, Integer current, boolean interrupt) {
        this.list = list;
        this.request = request;
        this.current = current;
        this.interrupt = interrupt;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        for (Integer integer : list) {
            if (integer >= 0)
                result.append(integer).append("  ");
            else result.append("&").append("  ");
            ;
        }
        return result.toString();
    }

    public String getList() {
        StringBuilder result = new StringBuilder();
        for (Integer integer : list) {
            if (integer >= 0)
                result.append(integer).append(request[list.indexOf(integer)] ? "*" : " ").append("  ");
            else result.append("& ").append("  ");
            ;
        }
        return result.toString();
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    public String isInterrupt() {
        return interrupt ? "T" : "F";
    }

    public void setInterrupt(boolean interrupt) {
        this.interrupt = interrupt;
    }
}
